#!/usr/bin/python
#
# list test
import os
import random

lists = ['a', 'b', 'c']

print("index: ", 'd' in lists)

print(len(lists))
# 0，1，2或者-1，-2，-3
print(lists[-1])

lists.append('d')

print(lists)
# 要删除指定位置的元素，用pop(i)方法，其中i是索引位置
lists.pop(2)
print(lists)

lists[2] = 'f'

print(lists)

'''
3
c
['a', 'b', 'c', 'd']
['a', 'b', 'd']
['a', 'b', 'f']

'''

# 元组
tuples = (1, 2, 3)

print(tuples)

print([x * x for x in range(1, 11)])  # [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

print([x * x for x in range(1, 11) if x % 2 == 0])  # [4, 16, 36, 64, 100]

print([m + n for m in 'ABC' for n in 'XYZ'])  # ['AX', 'AY', 'AZ', 'BX', 'BY', 'BZ', 'CX', 'CY', 'CZ']

print([d for d in os.listdir('.')])  # ['list.py', 'slice.py', 'num.py', 'for_if.py', 'string_test.py', 'dict_set.py']

L = ['Hello', 'World', 'IBM', 'Apple']
print([s.lower() for s in L])  # ['hello', 'world', 'ibm', 'apple']

# 排序
print(sorted([36, 5, -12, 9, -21]))  # [-21, -12, 5, 9, 36]

print(sorted(['bob', 'about', 'Zoo', 'Credit']))  # ['Credit', 'Zoo', 'about', 'bob'] 按照ASCII顺序排列

print(sorted(['bob', 'about', 'Zoo', 'Credit'], key=str.lower))  # ['about', 'bob', 'Credit', 'Zoo']

print(sorted(['bob', 'about', 'Zoo', 'Credit'], key=str.lower, reverse=True))  # ['Zoo', 'Credit', 'bob', 'about']  倒序


# list 随机排序
list_num = []
start = 73200
for i in range(100):
    list_num.append(start + i)
random.shuffle(list_num)
print(list_num)


list_words = ['a', 'b', 'c', 'd']
print(".".join(list_words[0:3]))  # a.b.c